package listener;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;

@WebListener
public class SessionAttributeListener implements HttpSessionAttributeListener {

    @Override
    public void attributeAdded(HttpSessionBindingEvent sbe) {

        //session添加属性时触发执行
        HttpSession session = sbe.getSession();
        System.out.println("session添加"+sbe.getName()+"属性,属性值："+
                session.getAttribute(sbe.getName()));

    }

    @Override
    public void attributeRemoved(HttpSessionBindingEvent sbe) {
        //session移除属性时触发执行
        HttpSession session = sbe.getSession();
        System.out.println("session移除"+sbe.getName()+"属性,属性值："+
                session.getAttribute(sbe.getName()));

    }

    @Override
    public void attributeReplaced(HttpSessionBindingEvent sbe) {
        //session修改属性时触发执行
        HttpSession session = sbe.getSession();
        System.out.println("session修改"+sbe.getName()+"属性,属性值："+
                session.getAttribute(sbe.getName()));

    }
}
